package org.fuys.coder.domain.audit.model.event;

import org.fuys.coder.common.entity.Pair;
import org.fuys.coder.domain.audit.model.req.AuditTask;
import org.fuys.coder.domain.audit.model.res.AuditResult;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @projectName: fuys-low-coder
 * @package: org.fuys.coder.domain.audit.model.event
 * @className: AsyncTaskIdHolder
 * @author: WangJing
 * @description: 用于保存内容审核的各个块的审核结果
 * @date: 2024/6/24 11:26
 * @version: 1.0
 */
public class AsyncTaskIdHolder {
    //记录任务和其需要的审核结果引用
    private static Map<String, List<AuditResult>> taskMap=new ConcurrentHashMap<>();

    private static Map<String, Pair<Integer,AtomicInteger>> taskNumsMap=new ConcurrentHashMap<>();

    private static Map<String, AuditTask> taskInfoMap=new ConcurrentHashMap<>();
    public static void setTasks(String id, List<AuditResult> tasks, Integer allNums){
        taskMap.put(id,tasks);
        taskNumsMap.put(id,new Pair<>(allNums,new AtomicInteger(0)));
    }
    public static List<AuditResult> getTasks(String id){
        return taskMap.get(id);
    }

    public static Integer getTaskNowNums(String id){
        return taskNumsMap.get(id).getRight().get();
    }

    public static Integer incrementTaskNowNums(String id){
        return taskNumsMap.get(id).getRight().incrementAndGet();
    }

    public static Integer getTaskAllNums(String id){
        return taskNumsMap.get(id).getLeft();
    }

    public static void removeMultipleTask(String id){
        taskNumsMap.remove(id);
        taskMap.remove(id);
    }

    public static void setTaskInfo(String id,AuditTask task){
        taskInfoMap.put(id,task);
    }

    public static AuditTask getTaskInfo(String id){
        return taskInfoMap.get(id);
    }

    public static void removeTaskInfo(String id){
        taskInfoMap.remove(id);
    }
}
